<template>
  <div class="app-container">
    <el-table
      v-loading="listLoading"
      element-loading-text="加载中"
      :data="list"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="序号" width="95">
        <template slot-scope="scope">
          {{ scope.$index+1 }}
        </template>
      </el-table-column>
      <el-table-column label="头像" width="61">
        <template slot-scope="scope">
          <el-avatar :src="scope.row.userAvatar" />
        </template>
      </el-table-column>
      <el-table-column label="昵称" width="200">
        <template slot-scope="scope">
          {{ scope.row.userName }}
        </template>
      </el-table-column>
      <el-table-column label="姓名" width="80">
        <template slot-scope="scope">
          {{ scope.row.realName }}
        </template>
      </el-table-column>
      <el-table-column label="手机号" width="120">
        <template slot-scope="scope">
          {{ scope.row.userPhone }}
        </template>
      </el-table-column>
      <el-table-column label="创建时间">
        <template slot-scope="scope">
          <i v-if="scope.row.bornTime" class="el-icon-time" />
          <span> {{ scope.row.bornTime }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column align="center" prop="created_at" label="Display_time" width="200">
        <template slot-scope="scope">
          <i class="el-icon-time" />
          <span>{{ scope.row.display_time }}</span>
        </template>
      </el-table-column> -->
    </el-table>
    <div class="block">
      <el-pagination
        :current-page="currentPage"
        :page-size="pageSize"
        layout="total, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
import { getList } from '@/api/wxuser'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  components: {

  },
  data() {
    return {
      list: null,
      listLoading: true,
      detailFrom: {},
      adType: [],
      currentPage: 1,
      total: 9,
      pageSize: 10
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    // 获取表格数据
    fetchData() {
      // debugger
      // console.log('路由模式', process.env.port)
      this.listLoading = true
      const val = {
        page: (this.currentPage - 1), size: this.pageSize
      }
      getList(val).then((res) => {
        console.log(res.res.content)
        this.list = res.res.content
        this.total = res.res.totalElements
        this.currentPage = res.res.number + 1
        this.pageSize = res.res.size
        this.listLoading = false
      })
    },

    // 分页
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`)
      this.pageSize = val
      this.fetchData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`)
      this.currentPage = val
      this.fetchData()
    }
  }
}
</script>
